import request from '@/utils/request'
import store from "@/store"

  //设备分页
  export const list = (query) => {
    return request({
      url: '/resource/device/page',
      method: 'get',
      params: query
    })
  }
  
  //修改设备
  export const updateObj = (obj) => {
    return request({
      url: '/resource/device',
      method: 'put',
      data: obj
    })
  }
  
  //新增设备
  export const addObj = (obj) => {
    return request({
      url: '/resource/device',
      method: 'post',
      data: obj
    })
  }

  //删除设备
  export const delObj = (deviceIds) => {
    return request({
      url: '/resource/device',
      method: 'delete',
      data: {
        deviceIds: deviceIds
      }
    })
  }

  //产品列表
  export const dict = (query) => {
    return request({
      url: '/resource/product/dict',
      method: 'get',
      params: query
    })
  }

  //产品数量
  export const summary = (query) => {
    return request({
      url: '/resource/device/summary',
      method: 'get',
      params: query
    })
  }

    //启用产品告警
    export const release = (deviceId) => {
      return request({
        url: '/resource​/device/release/' + deviceId,
        method: 'post'
      })
    }
  
     //停用产品告警
     export const unRelease = (deviceId) => {
      return request({
        url: '/resource​/device/unRelease/' + deviceId,
        method: 'post'
      })
    }

    //批量禁用
    export const batch = (obj) => {
      return request({
        url: '/resource​/device/unRelease/batch',
        method: 'post',
        data: obj
      })
    }

    //修改设备密钥
    export const deviceToken = (obj) => {
      return request({
        url: '/resource/device/token',
        method: 'put',
        data: obj
      })
    }

  //查询设备总数量
  export const fetchQueryDeviceCount = (deviceId) => {
    return request({
      url: '/resource/device/queryDeviceCount/' + deviceId,
      method: 'get'
    })
  }

   //获取设备基础信息
   export const fetchBasic = (deviceId) => {
    return request({
      url: '/resource/device/basic/' + deviceId,
      method: 'get'
    })
  }

  //所属品类
  export const fetchClass = (obj) => {
    return request({
      url: '/admin/dict/type/product_class',
      method: 'get',
      params: obj
    })
  }

  //设备导出
  export const exportFile = (query) => {
    return request({
      url: '/resource/device​/export',
      method: 'get',
      params: query
    })
  }

  //设备导入
  export const importFile = (obj) => {
    return request({
      url: '/resource/device​/import',
      headers: {
        Authorization: "Bearer " + store.getters.access_token,
      },
      responseType: 'blob',
      method: 'post',
      data: obj
    })
  }